<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
    <swiper-slide v-for="item of list" :key="item.id">
      <img class="swiper-img" :src="item.imgUrl" alt="去哪儿门票" />
    </swiper-slide>
    <!-- Options controls -->
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
  </div>
</template>
<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper >>> .swiper-pagination-bullet-active {
  background: #fff
}
.wrapper {
  overflow: hidden
  width: 100%
  height: 0
  padding-bottom: 31.25%
  // 注意让图片宽高保持相等写法
  // wrapper 高度相对于宽度会自动撑开31.25%
  // 保持了宽高比例始终是31.25%的比例
  // 也可以写成 width:100%;height:31.25vm 但有些浏览器支持不高，所以最好写成上面方式
  background: #eee
  .swiper-img {
    width: 100%
  }
}

</style>
